#pragma once

#include   <math.h>
#include    <error.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "MQTTClient.h"
#include "cJSON.h"
#include <stdbool.h>

#define ADDRESS     "tcp://192.168.0.168:1883"
#define CLIENTID    "Process_ClientSub"
#define CLIENTID_Pub    "ExampleClientPub"
#define TOPIC       "MQTT Examples"
#define QOS         1
#define TIMEOUT     10000L

#define CYCLE_MODE  1   //循环上报
#define REfresh_MODE    2   //刷新上报
#define Contrast_MODE   3   //对比上报

#define TEMP_CONTRAST    2
#define HUM_CONTRAST    3
#define LIGHT_CONTRAST  100

#define MSG_PATH "/tmp/ipc/msgqueue/peer/"

#define MAGIC_ID 'j'

typedef struct {//单片机各项数据
    int temperature;
    int humidity;
    int light;
    int fan;
    int motor;
    int buzzer;
    int LED1;
    int LED2;
    int LED3;
    int LED4;
} SensorData;

typedef struct {
    long msg_type;          // 消息类型
    size_t data_len;        // 数据长度
    char data[1024];        // 数据缓冲区
} MsgQueue;

//int  Client_Sub(MQTTClient client);


void connlost(void *context, char *cause);

int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *message);

void delivered(void *context, MQTTClient_deliveryToken dt);

int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *message);

void Empty_Control(const char *mqtt_json,char *temp);

char* serialize_sensor_data(const SensorData* data);

int deserialize_sensor_data(const char* json_string, SensorData* data);

int reconnect_mqtt();

